Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method 'bisect_right' and test #2

Merged
merged 2 commits into from
Oct 24, 2024
Merged

Conversation

tommyod
Copy link

@tommyod tommyod commented Oct 1, 2024

This is a method that I needed for my own usage of fenwick trees.

Adding it here as a proposed additional method too, along with a little test for it :)

dstein64 added a commit that referenced this pull request Oct 24, 2024
@dstein64 dstein64 merged commit 27d2b4b into dstein64:master Oct 24, 2024
18 checks passed
@dstein64
Copy link
Owner

Thanks @tommyod.

I made the following changes:

  • Renamed the function from bisect_right to find_stop
  • The returned value is one higher than you had, for consistency with the other functions, like prefix_sum.
  • Used a less strict criteria, but it can be modified with the strict argument
  • Your PR had j = 2 ** len(self). That starts the search outside the bounds of the array, thus resulting in unnecessary computation (successive bit shifts). For example, with a length of 100, j would be set to 2 ** 100 = 1267650600228229401496703205376.
  • The function now returns -1 for results that are out-of-range.

I've pushed the latest release to PyPI; it should be available now through pip.

@tommyod
Copy link
Author

tommyod commented Oct 25, 2024

Excellent, thanks!

@tommyod tommyod deleted the bisect_right branch October 26, 2024 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants